package calculator;

import java.util.ArrayList;
import java.util.List;


public class OperationAnalyzer {

	public Operation operation;
	public OperationAnalyzer(Operation operation) {
		super();
		this.operation = operation;
	}

	public int getNextOperationByPriority(List<String> tokens) {
		List<Integer> operations = getOperations(tokens);
		int indMaxPriority = -1;
		int maxPriority = -1;
		for (int i = 0; i < operations.size(); i++) {
			
			Integer operationIndex = operations.get(i);
			int priority = operation.getPriority(tokens.get(operationIndex));
			if (priority > maxPriority) {
				maxPriority = priority;
				indMaxPriority = operationIndex;
			}
		}
		return indMaxPriority;
	}

	public List<Integer> getOperations(List<String> tokens) {
		List <Integer> operations = new ArrayList<Integer>();
		for (int i = 0; i < tokens.size(); i++) {
			if (operation.isOperation(tokens.get(i))) {
				operations.add(i);
			}
		}
		return operations;
	}

}
